package cn.com.request;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "ResultServlet", value = "/ResultServlet")
public class ResultServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置响应内容类型为HTML，并使用UTF-8字符编码
        response.setContentType("text/html;charset=utf-8");
        // 获取PrintWriter对象，用于向客户端输出响应内容
        PrintWriter out = response.getWriter();
        // 从request作用域中获取名为"username"的属性值，并转换为String类型
        String username = (String) request.getAttribute("username");
        // 判断username是否不为null
        if (username != null) {
            // 向客户端输出用户名信息，并添加HTML换行标签
            out.println("用户名：" + username + "<br/>");
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
